package com.sanley.coronavirus.service.iml;

import com.github.pagehelper.PageHelper;
import com.sanley.coronavirus.bo.ReportBO;
import com.sanley.coronavirus.dao.ReportDao;
import com.sanley.coronavirus.dao.UserDao;
import com.sanley.coronavirus.entity.Report;
import com.sanley.coronavirus.entity.User;
import com.sanley.coronavirus.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

/**
 * @Author: ming
 * @create: 2022-11-17 18:48
 * @program: coronavirus
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportDao reportDao;

    @Autowired
    private UserDao userDao;

    @Override
    public int add(Report report, String username) {
        User user = userDao.selectUserInfoByUsername(username);
        report.setReportTime(new Date(System.currentTimeMillis()));
        report.setUserId(user.getId());
        return reportDao.add(report);
    }

    @Override
    public List<Report> getReportByUsername(String username) {
        User user = userDao.selectUserInfoByUsername(username);
        return reportDao.getReportByUserId(user.getId());
    }

    @Override
    public List<ReportBO> listAll(Integer page, Integer size, String keyword) {
        PageHelper.startPage(page, size);
        return reportDao.listAll(keyword);
    }
}
